<template>
  <view class="details-container">
    <!-- 顶部装饰 -->
    <view class="top-decoration"></view>

    <!-- 活动标题区域 -->
    <view class="activity-header">
      <text class="activity-title">{{itme.name}}</text>
      <view class="activity-meta">
        <text class="date">{{formatDate(itme.createTime)}}</text>
      </view>
    </view>

    <!-- 图片展示区域 -->
    <view class="images-section">
      <text class="section-title">活动图集</text>
      <view class="image-grid">
        <view 
          class="image-item" 
          v-for="(item, index) in imgList" 
          :key="index"
          @click="previewImage(index)"
        >
          <image 
            class="activity-image" 
            :src="avatarUrl + item" 
            mode="aspectFill"
          />
          <view class="image-overlay">
            <u-icon name="eye-fill" color="#fff" size="40"></u-icon>
          </view>
        </view>
      </view>
    </view>

    <!-- 活动介绍文本 -->
    <view class="description-section" v-if="itme.particulars">
      <view class="description-header">
        <u-icon name="info-circle-fill" size="32" color="#3c9cff"></u-icon>
        <text class="description-title">活动介绍</text>
      </view>
      <view class="description-content">
        <text class="description-text">{{ itme.particulars }}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      itme: {}, // 初始化为空对象
      avatarUrl: '', // 基础URL
      imgList: [], // 用来存储图片路径的数组
    };
  },
  onLoad(options) {
    if (options.itme) {
      this.itme = JSON.parse(options.itme); // 解析传递过来的itme对象
      this.avatarUrl = this.$baseUrl; // 基础URL
      if (this.itme.imgPath) {
        this.imgList = this.itme.imgPath.split(','); // 分割逗号分隔的图片路径
      }
    }
  },
  methods: {
    previewImage(index) {
      const imgUrls = this.imgList.map(item => this.avatarUrl + item);
      uni.previewImage({
        current: index, // 当前显示图片索引
        urls: imgUrls, // 需要预览的图片URL列表
      });
    },
    formatDate(timestamp) {
      if (!timestamp) return '';
      const date = new Date(timestamp);
      return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`;
    },
  },
};
</script>

<style lang="scss">
.details-container {
  min-height: 100vh;
  background: linear-gradient(to bottom, #f0f5ff, #ffffff);
  padding: 20rpx;
  padding-bottom: 40rpx;
}

.top-decoration {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 200rpx;
  background: linear-gradient(to bottom right, #3c9cff, #5dabff);
  border-bottom-left-radius: 50% 20%;
  border-bottom-right-radius: 50% 20%;
  opacity: 0.1;
  z-index: 1;
}

.activity-header {
  margin: 30rpx 0;
  padding: 0 20rpx;
  
  .activity-title {
    font-size: 40rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 16rpx;
    display: block;
  }
  
  .activity-meta {
    .date {
      font-size: 26rpx;
      color: #999;
    }
  }
}

.images-section {
  background: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);

  .section-title {
    font-size: 32rpx;
    font-weight: 500;
    color: #333;
    margin-bottom: 20rpx;
    display: block;
  }

  .image-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20rpx;
  }

  .image-item {
    position: relative;
    border-radius: 12rpx;
    overflow: hidden;
    aspect-ratio: 1;

    .activity-image {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .image-overlay {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(0, 0, 0, 0.3);
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 0.3s ease;
    }

    &:active .image-overlay {
      opacity: 1;
    }
  }
}

.description-section {
  background: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);

  .description-header {
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;

    .description-title {
      font-size: 32rpx;
      font-weight: 500;
      color: #333;
      margin-left: 12rpx;
    }
  }

  .description-content {
    background: #f8f9fc;
    border-radius: 12rpx;
    padding: 20rpx;

    .description-text {
      font-size: 28rpx;
      color: #666;
      line-height: 1.6;
    }
  }
}
</style>